package com.housekeeping.housekeeping.order.wxPay.controller;

import com.housekeeping.housekeeping.order.utils.ResponseEntity;
import com.housekeeping.housekeeping.order.utils.ResponseUtils;
import com.housekeeping.housekeeping.order.wxPay.entity.Account;
import com.housekeeping.housekeeping.order.wxPay.service.OrderPayServ;
import com.housekeeping.housekeeping.order.wxPay.service.impl.OrderPayServImpl;
import com.housekeeping.housekeeping.order.wxPay.utils.WXPayCode;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/wxPay/add")
public class AddAccountController extends HttpServlet {
    private OrderPayServ orderPayServ = new OrderPayServImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        long money = Integer.parseInt(req.getParameter("money"));
//        Account account = AccountUtils.verifyAccount(req);       先假定定一个账户
        Account account = new Account("abc123","zs","123456789");
        ResponseEntity<Long> entity = null;

        try {
            entity = orderPayServ.addOrder(money, account);
        } catch (SQLException throwables) {
            entity = ResponseEntity.error(WXPayCode.ADD_ACCOUNT_ERROR);
        }

        //返回订单信息
        ResponseUtils.deliver(resp, entity);
    }
}
